package org.jeecg.trace.service.impl;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.trace.dto.BarCodeTraceDTO;
import org.jeecg.trace.dto.PackageBoxDTO;
import org.jeecg.trace.dto.PackageProductDTO;
import org.jeecg.trace.entity.MesPackItem;
import org.jeecg.trace.entity.MesUnitHistory;
import org.jeecg.trace.entity.MesUnitStatus;
import org.jeecg.trace.entity.MesUnitid;
import org.jeecg.trace.mapper.PackageTraceMapper;
import org.jeecg.trace.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class PackageTraceServiceImpl implements PackageTraceService {
    @Autowired
    private PackageTraceMapper packageTraceMapper;
    @Autowired
    private IMesPackItemService iMesPackItemService;
    @Autowired
    private IMesUnitStatusService iMesUnitStatusService;
    @Autowired
    private IMesUnitHistoryService iMesUnitHistoryService;
    @Autowired
    private IMesUnitidService iMesUnitidService;
    @Override
    public IPage<PackageBoxDTO> listBoxPackage(Page<PackageBoxDTO> page, Map<String, String> map) {
        return packageTraceMapper.listBoxPackage(page,map);
    }

    @Override
    public IPage<PackageProductDTO> listProductPackage(Page<PackageProductDTO> page, Map<String, String> map) {
        return packageTraceMapper.listProductPackage(page,map);
    }

    @Override
    public void unbindPackage(String unitsn) {
        //删除status
        iMesUnitStatusService.remove(new QueryWrapper<MesUnitStatus>().eq("UNITSN", unitsn));
        //删除history
        iMesUnitHistoryService.remove(new QueryWrapper<MesUnitHistory>().eq("UNITSN", unitsn));
        //删除unitId
        iMesUnitidService.remove(new QueryWrapper<MesUnitid>().eq("UNITSN", unitsn));
    }
}
